Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new encoder for client and server #158

Merged
merged 10 commits into from
Nov 28, 2020
Merged

new encoder for client and server #158

merged 10 commits into from
Nov 28, 2020

Conversation

jbr
Copy link
Member

@jbr jbr commented Nov 24, 2020

this is based on #157. the changes in this pr are d80934d

@jbr jbr mentioned this pull request Nov 25, 2020
Copy link
Member

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gosh this is fantastic imo! Some comments, and I am sure @yoshuawuyts may also have some.

src/client/encode.rs Outdated Show resolved Hide resolved

self.finalize_headers()?;
let mut headers = self.request.iter().collect::<Vec<_>>();
headers.sort_unstable_by_key(|(h, _)| if **h == HOST { "0" } else { h.as_str() });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that we'd be better off using some kind of order-stable hashmap rather that doing a sort here, since this sort could be O(n log(n)). Not sure if a good one exists though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah… this logic also probably belongs in http-types, but as mentioned elsewhere i think that should be a distinct move from this change

bytes_read += len;
}
loop {
self.state = match self.state {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really neat!


/// like ready! but early-returns the Poll<Result<usize>> early in all situations other than Ready(Ok(0))
#[macro_export]
macro_rules! read_to_end {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems useful generally tbh

// Else continue encoding
self.encode_fixed_body(cx, buf)
if self.response.header(DATE).is_none() {
let date = fmt_http_date(SystemTime::now());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not critical, but this should probably be cached, Node.js does it to the minute: https://github.com/nodejs/node/blob/4f0f2e713848817d49a4105a0736db2dfeed061e/lib/internal/http.js#L19-L29

(I may be willing to that in a follow-up pr.)

src/server/encode.rs Outdated Show resolved Hide resolved
src/server/encode.rs Outdated Show resolved Hide resolved
tests/server_encode.rs Outdated Show resolved Hide resolved
byte-pool = "0.2.1"
lazy_static = "1.4.0"
futures-core = "0.3.1"
log = "0.4"
pin-project = "1.0.2"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in theory, pin-project-lite 0.2 has enum pinning, but i couldn't figure out how to get it to work correctly

Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch is fascinating, and so good. Very excited for the simplifications this PR bring. In conjunction with the more robust test suite this is incredible work all around!

src/chunked/encoder.rs Outdated Show resolved Hide resolved
This was referenced Nov 27, 2020
@jbr jbr merged commit 66b887d into main Nov 28, 2020
@delete-merged-branch delete-merged-branch bot deleted the new-encoder branch November 28, 2020 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants